package com.drug.web.controller.wms;

import com.drug.common.annotation.Log;
import com.drug.common.core.controller.BaseController;
import com.drug.common.core.domain.AjaxResult;
import com.drug.common.core.page.TableDataInfo;
import com.drug.common.enums.BusinessType;
import com.drug.common.utils.poi.ExcelUtil;
import com.drug.wms.domain.BusCargoSpaceConf;
import com.drug.wms.service.IBusCargoSpaceConfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 货位配置Controller
 *
 * @author ruoyi
 * @date 2021-12-26
 */
@RestController
@RequestMapping("/wms/space")
@Api("货位配置")
public class BusCargoSpaceConfController extends BaseController {
    @Autowired
    private IBusCargoSpaceConfService busCargoSpaceConfService;

    /**
     * 查询货位配置列表
     */
    @PreAuthorize("@ss.hasPermi('wms:space:list')")
    @GetMapping("/list")
    @ApiOperation("查询货位配置列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warehouseId", value = "仓库id", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "spaceName", value = "货位名称", dataType = "String", dataTypeClass = String.class),
          })
    public TableDataInfo list(BusCargoSpaceConf busCargoSpaceConf) {
        startPage();
        List<BusCargoSpaceConf> list = busCargoSpaceConfService.selectBusCargoSpaceConfList(busCargoSpaceConf);
        return getDataTable(list);
    }

    /**
     * 导出货位配置列表
     */
    @PreAuthorize("@ss.hasPermi('wms:space:export')")
    @Log(title = "货位配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusCargoSpaceConf busCargoSpaceConf) {
        List<BusCargoSpaceConf> list = busCargoSpaceConfService.selectBusCargoSpaceConfList(busCargoSpaceConf);
        ExcelUtil<BusCargoSpaceConf> util = new ExcelUtil<BusCargoSpaceConf>(BusCargoSpaceConf.class);
        return util.exportExcel(list, "货位配置数据");
    }

    /**
     * 获取货位配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:space:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(busCargoSpaceConfService.selectBusCargoSpaceConfById(id));
    }

    /**
     * 新增货位配置
     */
    @PreAuthorize("@ss.hasPermi('wms:space:add')")
    @Log(title = "货位配置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增货位配置")
    public AjaxResult add(@RequestBody BusCargoSpaceConf busCargoSpaceConf) {
        return toAjax(busCargoSpaceConfService.insertBusCargoSpaceConf(busCargoSpaceConf));
    }

    /**
     * 修改货位配置
     */
    @PreAuthorize("@ss.hasPermi('wms:space:edit')")
    @Log(title = "货位配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusCargoSpaceConf busCargoSpaceConf) {
        return toAjax(busCargoSpaceConfService.updateBusCargoSpaceConf(busCargoSpaceConf));
    }

    /**
     * 删除货位配置
     */
    @PreAuthorize("@ss.hasPermi('wms:space:remove')")
    @Log(title = "货位配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(busCargoSpaceConfService.deleteBusCargoSpaceConfByIds(ids));
    }
}
